<template>
	<view>
		<navView navTitle="荣誉积分榜" backgroundColor="#008efe" titleColor="#fff"></navView>
		<image class="banner" src="https://hfd.bjlzkj.com/static/ranking/ranking_banner.png" mode=""></image>
		<view class="banview"></view>
		<view class="list">
			<view class="top" v-if="ranking.length > 0">
				<!-- 循环前3名 -->
				<view class="item1 item" 
					v-for="(item, index) in ranking.slice(0, 3)" 
					:key="item.id"
					@tap="$navTo('/pages/user/score?id=' + item.id)">
					<image :src="`https://hfd.bjlzkj.com/static/ranking/vip${index + 1}.png`" mode=""></image>
					<view class="name">
						{{ item.name }}
					</view>
					<view class="num">
						{{ item.score }}
					</view>
				</view>
			</view>

			<view class="lists" v-if="ranking.length > 3">
				<view class="title">
					<!-- 标题保持不变 ... -->
				</view>
				<!-- 循环剩余排名 -->
				<view class="li" v-for="(item, index) in ranking.slice(3)" 
					:key="item.id" 
					@tap="$navTo('/pages/user/score?id=' + item.id)">
					<view class="item">
						<view class="ind">
							{{ item.rank }}
						</view>
						<view class="name">
							{{ item.name }}
						</view>
						<view class="scope">
							{{ item.score }}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ranking:[],
			}
		},
		onLoad(){
			this.getRanking()
		},
		methods: {
			getRanking() {
				this.$request('/addons/qingdong/statistics/scoreRanding', 'GET').then(res => {
					console.log(res.data, 'data')
					this.ranking = res.data || [] // 添加空值处理
				}).catch(err => {
					console.error('请求失败:', err)
					this.ranking = [] // 失败时重置为空数组
				})
			}
		}
	}
</script>

<style lang="scss">
	.banner {
		width: 100%;
		height: 460rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
	}

	.banview {
		width: 100%;
		height: 252rpx;
		position: fixed;
		top: 460rpx;
		left: 0;
		z-index: -1;
		background: linear-gradient(180deg, #0085F9 0%, #F5F6F9 100%);
	}

	.list {
		width: 90%;
		background: #fff;
		border-radius: 16rpx;
		padding: 20rpx;
		box-sizing: border-box;
		margin: 0 auto;
		margin-top: 280rpx;

		.top {
			display: flex;
			align-items: center;
			margin-top: -60rpx;
			justify-content: space-around;

			.item:nth-child(2) {
				margin-top: -60rpx;
			}

			.item {
				width: 174rpx;
				height: 277rpx;
				background: -webkit-linear-gradient(top, #E1F0F8, #FFFFFF);
				border-radius: 22rpx;
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				justify-content: center;
				box-shadow: 0 0 20rpx -10rpx #ccc;

				image {
					width: 70rpx;
					height: 70rpx;
				}

				.name {
					width: 100%;
					text-align: center;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
				}

				.num {
					width: 100%;
					text-align: center;
					font-weight: bold;
					font-size: 48rpx;
					color: #333333;
				}
			}
		}

		.lists {
			width: 100%;
			margin-top: 10rpx;

			.title {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-around;

				.item {
					font-weight: 400;
					font-size: 30rpx;
					color: #999999;
				}
			}

			.li {
				width: 100%;

				.item:last-child {
					border: 0;
				}

				.item {
					display: flex;
					align-items: center;
					justify-content: space-around;
					font-weight: 400;
					font-size: 30rpx;
					color: #333333;
					border-bottom: 1rpx solid #ccc;
					padding: 20rpx;
					box-sizing: border-box;
				}
			}
		}
	}
</style>